package com.babyqiao.wallpaper.manager.service.impl;

import com.babyqiao.wallpaper.manager.controller.dto.CategoryPicQuery;
import com.babyqiao.wallpaper.manager.dao.CategoryPicMapper;
import com.babyqiao.wallpaper.manager.entity.WallpaperCategoryPic;
import com.babyqiao.wallpaper.manager.service.CategoryPicService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author qinglongzhai
 * @date 2020/12/15
 */
@Service
public class CategoryPicServiceImpl extends ServiceImpl<CategoryPicMapper, WallpaperCategoryPic> implements CategoryPicService {

    /**
     * 添加查询条件
     *
     * @param categoryPicQuery 查询参数类
     * @return 条件wrapper
     */
    @Override
    public QueryWrapper<WallpaperCategoryPic> addSelectCondition(CategoryPicQuery categoryPicQuery) {
        QueryWrapper<WallpaperCategoryPic> queryWrapper = new QueryWrapper<>();
        String categoryId = categoryPicQuery.getCategoryId();
        String name = categoryPicQuery.getName();
        String online = categoryPicQuery.getOnline();
        String startTime = categoryPicQuery.getStartTime();
        String endTime = categoryPicQuery.getEndTime();

        if (categoryId != null) {
            queryWrapper.eq("category_id", categoryId);
        }
        if (name != null) {
            queryWrapper.like("name", name);
        }
        if (online != null) {
            queryWrapper.eq("online", online);
        }
        if (startTime != null) {
            queryWrapper.ge("gmt_modified", startTime);
        }
        if (endTime != null) {
            queryWrapper.le("gmt_modified", endTime);
        }
        queryWrapper.orderByDesc("gmt_modified");


        return queryWrapper;
    }

    /**
     * 修改上线状态
     *
     * @param id
     * @param state :
     * @Author QLZ
     * @Date 2020/12/17
     * * @param id:
     */
    @Override
    public UpdateWrapper<WallpaperCategoryPic> addUpdataCondition(String id, Integer state) {
        UpdateWrapper<WallpaperCategoryPic> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.set("online", state);
        return updateWrapper;
    }
}
